﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using QLTV_V2.DataAccess;
using QLTV_V2.BussinessObject;

namespace QLTV_V2.BussinessLogic
{
    class SachBUS
    {
        ConnectData conn = new ConnectData();
        Utilities uti = new Utilities();
        DataTable tb = new DataTable();
        PhieuKiemKe phieuKK = new PhieuKiemKe();
        PhieuThanhLy phieuTL = new PhieuThanhLy();
        private string sql;
        #region Các hàm dùng cho lập dự toán mua sách
        //Lấy thông tin phiếu dự toán theo mã phiếu
        public PhieuDuToan GetPhieuDuToan_Object(string maphieu)
        {
            sql = "select * from PhieuDuToan where MaPhieuDuToan='" + maphieu + "'";
            PhieuDuToan dt = new PhieuDuToan();
            DataRow dr = conn.GetDataTable(sql).Rows[0];
            dt.MaPhieuDuToan = dr["MaPhieuDuToan"].ToString();
            dt.TenPhieu = dr["TenPhieu"].ToString();
            dt.NgayLap = Convert.ToDateTime(dr["NgayLap"]);
            dt.MaNV = dr["MaNV"].ToString();
            return dt;
        }
        //Insert/Update/Delete Phieu du toan
        public bool InsertPhieuDuToan(PhieuDuToan dt)
        {
            int type = uti.GetTypeDate();
            sql = "insert into PhieuDuToan values(N'" + dt.MaPhieuDuToan + "',N'" + dt.TenPhieu + "',convert(datetime,'" + dt.NgayLap.ToShortDateString() + "'," + type + "),N'" + dt.MaNV + "')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        public bool UpdatePhieuDuToan(PhieuDuToan dt, string maphieu)
        {
            int type = uti.GetTypeDate();
            sql = "update PhieuDuToan set " +
                    "TenPhieu=N'" + dt.TenPhieu + "',NgayLap=convert(datetime,'" + dt.NgayLap.ToShortDateString() + "'," + type + "),MaNV=N'" + dt.MaNV + "' " +
                    "where MaPhieuDuToan=N'" + maphieu + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        //-----------CT phieu du toan
        public DataTable GetCTPhieuDuToan(string maphieudutoan)
        {
            sql = "select MaCTDuToan,MaPhieuDuToan,MaLoaiSach,TenDauSach,SoLuong, DonGia, SoLuong*DonGia as 'ThanhTien' "+
                  "from CTPhieuDuToan where MaPhieuDuToan=N'" + maphieudutoan + "'";
            return conn.GetDataTable(sql);
        }
        public bool InsertCTPhieuDuToan(CTPhieuDuToan ct)
        {
            sql = "insert into CTPhieuDuToan values(N'" + ct.MaCTDuToan + "',N'" + ct.MaPhieuDuToan + "',N'" + ct.MaLoaiSach + "',N'" + ct.TenDauSach + "'," + ct.SoLuong + ",'" + ct.DonGia + "')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        public bool UpdateCTPhieuDuToan(CTPhieuDuToan ct)
        {
            sql = "update CTPhieuDuToan set " +
                    "MaLoaiSach=N'" + ct.MaLoaiSach + "',TenDauSach=N'" + ct.TenDauSach + "',SoLuong=" + ct.SoLuong + ",DonGia=" + ct.DonGia + "" +
                    " where MaCTDuToan=N'" + ct.MaCTDuToan + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        #endregion
        
        #region Dùng cho nhập sách
        //Dùng cho xuất file mẫu
        public DataTable getSource_FileMau_NhapSach()
        {
            sql = "select top 10 ROW_NUMBER() OVER (Order by TenDauSach) as 'STT', "+ 
                "MaLoaiSach as 'Mã kho', TenDauSach as 'Nhan đề', SoLuongNhap as 'Số lượng', "+
                "DonGia as 'Đơn giá', SoLuongNhap* DonGia as 'Thành tiền' "+
                "from CTPhieuNhap";
            return conn.GetDataTable(sql);
        }

        //Dùng cho phiếu nhập
        public DataTable GetPhieuNhap()
        {
            sql = "select * from PhieuNhap order by MaPhieuNhap";
            return conn.GetDataTable(sql);
        }
       
        public PhieuNhap GetPhieuNhap_Object(string maphieunhap)
        {
                PhieuNhap phieunhap = new PhieuNhap();
                sql = "select * from PhieuNhap where MaPhieuNhap=N'" + maphieunhap + "'";
                try
                {
                    DataRow dr = conn.GetDataTable(sql).Rows[0];
                    phieunhap.MaPhieuNhap = dr["MaPhieuNhap"].ToString();
                    phieunhap.LyDoNhap = dr["LyDoNhap"].ToString();
                    phieunhap.NgayNhap = Convert.ToDateTime(dr["NgayNhap"]);
                    phieunhap.SoHDCT = dr["SoHDCT"].ToString();
                    phieunhap.MaNCC = dr["MaNCC"].ToString();
                    phieunhap.MaNV = dr["MaNV"].ToString();
                }
                catch
                {
                   // MessageBox.Show("Không thể tìm thấy thông tin","Thông báo");
                }
                return phieunhap;
        }
       
        public bool insertPhieuNhap(PhieuNhap phieunhap)
        {
            int type = uti.GetTypeDate();
            sql = "insert into PhieuNhap values(" +
                    "N'" + phieunhap.MaPhieuNhap + "',N'" + phieunhap.LyDoNhap + "',convert(datetime,'" + phieunhap.NgayNhap + "'," + type + ")," +
                    "N'" + phieunhap.SoHDCT + "',N'" + phieunhap.MaNCC + "',N'" + phieunhap.MaNV + "')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        
        public bool updatePhieuNhap(PhieuNhap phieunhap, string maphieunhap)
        {
            int type = uti.GetTypeDate();
            sql = "update PhieuNhap set" +
                    " MaPhieuNhap=N'" + phieunhap.MaPhieuNhap + "',LyDoNhap=N'" + phieunhap.LyDoNhap + "',NgayNhap=convert(datetime,'" + phieunhap.NgayNhap + "'," + type + ")," +
                    " SoHDCT=N'" + phieunhap.SoHDCT + "',MaNCC=N'" + phieunhap.MaNCC + "'" +
                    " where MaPhieuNhap=N'" + maphieunhap + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        
        public bool checkSavePhieuNhap(PhieuNhap phieunhap)
        {
            if (phieunhap.LyDoNhap.Equals(""))
            {
                MessageBox.Show("Chưa nhập lý do");
                return false;
            }
            return true;
        }
        
        //Dungf cho CTPhieuNhap
        public DataTable getPhieuNhap_show()
        { 
            sql="select NgayNhap,b.MaPhieuNhap, MaCTPhieuNhap, MaLoaiSach, TenDauSach, SoLuongNhap, DonGia, SoLuongNhap*DonGia as 'ThanhTien', TenNCC, BienMuc, DKMaCB "+
                "from NhaCungCap a join PhieuNhap b on a.MaNCC=b.MaNCC "+
	            "join CTPhieuNhap c on b.MaPhieuNhap=c.MaPhieuNhap "+
                "group by NgayNhap,b.MaPhieuNhap,c.MaCTPhieuNhap,MaLoaiSach,TenDauSach,SoLuongNhap, DonGia, TenNCC,BienMuc,DKMaCB "+
                "order by BienMuc, DKMaCB, NgayNhap";
            return conn.GetDataTable(sql);
        }
        
        public DataTable getCTPhieuNhap(string maphieunhap)
        {
            sql = "select MaCTPhieuNhap,MaLoaiSach,TenDauSach,SoLuongNhap,DonGia,SoLuongNhap*DonGia as 'ThanhTien' from CTPhieuNhap where MaPhieuNhap=N'" + maphieunhap + "'";
            return conn.GetDataTable(sql);
        }
        
        public CTPhieuNhap GetCTPhieuNhap_Object(string mactphieunhap)
        {
            CTPhieuNhap CT = new CTPhieuNhap();
            sql = "select * from CTPhieuNhap where MaCTPhieuNhap=N'" + mactphieunhap + "'";
            try
            {
                DataRow dr = conn.GetDataTable(sql).Rows[0];
                CT.MaCTPhieuNhap = dr["MaCTPhieuNhap"].ToString();
                CT.MaPhieuNhap = dr["MaPhieuNhap"].ToString();
                CT.MaLoaiSach = dr["MaLoaiSach"].ToString();
                CT.TenDauSach = dr["TenDauSach"].ToString();
                CT.SoLuongNhap = Convert.ToInt32(dr["SoLuongNhap"]);
                CT.DonGia = Convert.ToDouble(dr["DonGia"]);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy thông tin","Thông báo");
            }
            return CT;
        }
        
        //Thêm CT phiếu nhập sách
        public bool insertCTPhieuNhap(CTPhieuNhap ct)
        {
            sql = "insert into CTPhieuNhap values (" +
                "N'" + ct.MaCTPhieuNhap + "',N'" + ct.MaPhieuNhap + "',N'" + ct.MaLoaiSach + "',N'" + ct.TenDauSach + "'," + ct.SoLuongNhap + "," + ct.DonGia + ",'" + ct.BienMuc + "','" + ct.DKMaCB + "')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        
        //Update chi tiết phiếu nhập
        public bool updateCTPhieuNhap(CTPhieuNhap ct, string mact)
        {
            sql = "update CTPhieuNhap set " +
                  " MaLoaiSach=N'" + ct.MaLoaiSach + "',TenDauSach=N'" + ct.TenDauSach + "',SoLuongNhap=" + ct.SoLuongNhap + ",DonGia=" + ct.DonGia + "" +
                  " where MaCTPhieuNhap=N'" + mact + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
       
        //Update sau khi có thay đổi trong biên mục
        public bool updateCTPhieuNhap_After(string mact, string tendausach, string maloaisach, double giabia)
        {
            sql = "update CTPhieuNhap set MaLoaiSach=N'" + maloaisach + "',TenDauSach=N'" + tendausach + "',DonGia ="+giabia+" "+
                  "where MaCTPhieuNhap=N'" + mact + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        
        //update sau khi biên muc/ dk mã cá biệt
        public bool update_After_BM_DK(string mact,int k)
        {
            if (k == 1)//update trạng thái bien muc
                sql = "update CTPhieuNhap set BienMuc='true' where MaCTPhieuNhap=N'"+mact+"'";
            else //update trạng thái đk mã cá biệt.
                sql = "update CTPhieuNhap set DKMaCB='true' where MaCTPhieuNhap=N'"+mact+"'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        
        //Kiem tra truoc kh lưu
        public bool checkSaveCTPhieuNhap(CTPhieuNhap ct)
        {
            if (ct.TenDauSach.Equals(""))
            {
                MessageBox.Show("Chưa nhập tên ấn phẩm","Thông báo");
                return false;
            }
            if (ct.SoLuongNhap <= 0 || uti.checkDigit(ct.SoLuongNhap.ToString()) == false)
            {
                MessageBox.Show("Số lượng nhập không hợp lệ","Thông báo");
                return false;
            }
            if (ct.DonGia <= 0 || uti.checkDigit(ct.DonGia.ToString()) == false)
            {
                MessageBox.Show("Đơn giá không hợp lệ");
                return false;
            }
            return true;
        }
        #endregion
        
        #region Các hàm dùng cho biên mục
        //Dùng cho tìm kiếm biên mục trùng
        public DataTable getDauSach(string tendausach)
        {
            sql = "select MaDauSach, TenDauSach,MaLoaiSach,TenTacGia,TenNXB, NamXB, KHPhanLoai " +
                "from TacGia a join DauSach b on a.MaTacGia=b.MaTacGia " +
                "join NhaXuatBan c on b.MaNXB=c.MaNXB " +
                "where TenDauSach like N'%" + tendausach + "%' " +
                "group by MaDauSach, TenDauSach,MaLoaiSach,TenTacGia,TenNXB, NamXB, KHPhanLoai " +
                "order by MaDauSach";
            return conn.GetDataTable(sql);
        }
       
        public DauSach getDauSach_object(string tendausach,string maloaisach,string madausach, int dk)
        {
            DauSach ds = new DauSach();
            if (dk == 1)
                sql = "select * from DauSach where TenDauSach=N'" + tendausach + "' and MaLoaiSach=N'" + maloaisach + "'";
            else
                sql = "select * from DauSach where MaDauSach=N'" + madausach + "'";
            try
            {
                DataRow dr = conn.GetDataTable(sql).Rows[0];
                ds.MaDauSach = dr["MaDauSach"].ToString();
                ds.TenDauSach = dr["TenDauSach"].ToString();
                ds.MaLoaiSach = dr["MaLoaiSach"].ToString();
                ds.MaTacGia = dr["MaTacGia"].ToString();
                ds.MaNXB = dr["MaNXB"].ToString();
                ds.KHPhanLoai = dr["KHPhanLoai"].ToString();
                ds.SoISBN = dr["SoISBN"].ToString();
                ds.MaNgonNgu = dr["MaNgonNgu"].ToString();
                ds.GiaBia = Convert.ToDouble(dr["GiaBia"]);
                ds.SoTrang = Convert.ToInt32(dr["SoTrang"]);
                ds.KhoGiay = dr["KhoGiay"].ToString();
                ds.HinhThucBia = dr["HinhThucBia"].ToString();
                ds.NamXB=Convert.ToInt32(dr["NamXB"]);
                ds.LanXB = dr["LanXB"].ToString();
                ds.SoPH = dr["SoPH"].ToString();
                ds.NgayPH = Convert.ToDateTime(dr["NgayPH"]);
                ds.TLKemTheo = dr["TLKemTheo"].ToString();
                ds.AnhBia = dr["AnhBia"].ToString();
                ds.ViTriTam = dr["ViTriTam"].ToString();
                ds.SoLuongTam = Convert.ToInt32(dr["SoLuongTam"]);
                ds.NhanDeSongsong = dr["NhanDeSongsong"].ToString();
                ds.DongTacGia = dr["DongTacGia"].ToString();
                ds.PhuDe = dr["PhuDe"].ToString();
                ds.BienDich = dr["BienDich"].ToString();
                ds.TomtatND = dr["TomTatND"].ToString();
                ds.DangLuuTru = dr["DangLuuTru"].ToString();
            }
            catch
            {
                MessageBox.Show("Không thể tìm thấy thông tin","Thông báo");
            }
            return ds;
        }
        //Lây tên tác giả theo mã tác giả
        public string getTenTG(string maTG)
        {
                sql = "select TenTacGia from TacGia where MaTacGia=N'" + maTG + "'";
                    DataRow dr = conn.GetDataTable(sql).Rows[0];
                    return dr["TenTacGia"].ToString();
        }
        public string getTenNXB(string maNXB)
        {
                sql = "select TenNXB from NhaXuatBan where MaNXB=N'" + maNXB + "'";
                DataRow dr = conn.GetDataTable(sql).Rows[0];
                return dr["TenNXB"].ToString();
        }
        public bool insertDauSach(DauSach ds)
        {
            int type=uti.GetTypeDate();
            sql = "insert into DauSach values(" +
                  "N'" + ds.MaDauSach + "',N'" + ds.TenDauSach + "',N'" + ds.MaLoaiSach + "',N'" + ds.MaTacGia + "',N'" + ds.MaNXB + "'," +
                  "N'" + ds.KHPhanLoai + "',N'" + ds.SoISBN + "',N'" + ds.MaNgonNgu + "'," + ds.GiaBia + "," + ds.SoTrang + ",N'" + ds.KhoGiay + "'," +
                  "N'" + ds.HinhThucBia + "'," + ds.NamXB + ",N'" + ds.LanXB + "',N'" + ds.SoPH + "',convert(datetime,'" + ds.NgayPH.ToShortDateString() + "'," + type + ")," +
                  "N'"+ds.TLKemTheo+"',N'"+ds.AnhBia+"',N'"+ds.ViTriTam+"',"+ds.SoLuongTam+",N'"+ds.NhanDeSongsong+"',N'"+ds.DongTacGia+"',N'"+ds.PhuDe+"',N'"+ds.BienDich+"',N'"+ds.TomtatND+"',N'"+ds.DangLuuTru+"')";
            if(conn.ExecuteQuery(sql)==true)
                return true;
            return false;
        }
        public bool updateDauSach(DauSach ds, string madausach)
        {
            int type = uti.GetTypeDate();
            sql = "update DauSach set " +
                  "MaDauSach=N'"+ds.MaDauSach+"',TenDauSach=N'" + ds.TenDauSach + "',MaLoaiSach=N'" + ds.MaLoaiSach + "',MaTacGia=N'" + ds.MaTacGia + "',MaNXB=N'" + ds.MaNXB + "'," +
                  "KHPhanLoai=N'" + ds.KHPhanLoai + "',SoISBN=N'" + ds.SoISBN + "',MaNgonNgu=N'" + ds.MaNgonNgu + "',GiaBia=" + ds.GiaBia + "," +
                  "SoTrang=" + ds.SoTrang + ",KhoGiay=N'" + ds.KhoGiay + "',HinhThucBia=N'" + ds.HinhThucBia + "',NamXB=" + ds.NamXB + ",LanXB=N'" + ds.LanXB + "',SoPH=N'" + ds.SoPH + "'," +
                  "NgayPH=convert(datetime,'" + ds.NgayPH.ToShortDateString() + "'," + type + "),TLKemTheo=N'" + ds.TLKemTheo + "',AnhBia=N'" + ds.AnhBia + "',ViTriTam=N'" + ds.ViTriTam + "', " +
                  "NhanDeSongSong=N'" + ds.NhanDeSongsong + "',DongTacGia=N'" + ds.DongTacGia + "',PhuDe=N'" + ds.PhuDe + "',BienDich=N'" + ds.BienDich + "',TomTatND=N'" + ds.TomtatND + "',DangLuuTru=N'" + ds.DangLuuTru + "'" +
                  "where MaDauSach=N'"+madausach+"'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        #endregion
       
        #region Các hàm dùng cho đăng kí mã cá biệt
        public DataTable getBanSach(string madausach)
        {
            sql = "select MaBanSach, MaDauSach as 'MaDauSach1', NgayCN, TinhTrang, TrangThai, MaViTri from BanSach where MaDauSach='" + madausach + "'";
            return conn.GetDataTable(sql);
        }
        public bool insertBanSach(BanSach bs)
        {
            int type=uti.GetTypeDate();
            sql = "insert into BanSach values(" +
                  "N'"+bs.MaBanSach+"',N'"+bs.MaDauSach+"',convert(datetime,'"+bs.NgayCN.ToShortDateString()+"',"+type+"),N'"+bs.MaViTri+"',N'"+bs.TinhTrang+"',N'"+bs.TrangThai+"')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        #endregion
      
        #region Dùng cho Kiểm kê ấn phẩm
        //Các hàm lấy thông tin phieu kiem ke--> object
        public PhieuKiemKe getPhieuKK_object(string maphieukk)
        {
            sql = "select * from PhieuKiemKe where MaPhieuKK='" + maphieukk + "'";
            try {
                DataRow dr = conn.GetDataTable(sql).Rows[0];
                phieuKK.MaPhieuKK = dr["MaPhieuKK"].ToString();
                phieuKK.TenPhieuKK = dr["TenPhieuKK"].ToString();
                phieuKK.NgayKK = Convert.ToDateTime(dr["NgayKK"]);
                phieuKK.MaNV = dr["MaNV"].ToString();
            }
            catch
            {
                MessageBox.Show("Không tìm thấy thông tin","Thông báo");
            }
            return phieuKK;
        }
        //Theem phieu kiem ke
        public bool insertPhieuKK(PhieuKiemKe pkk)
        {
            int type = uti.GetTypeDate();
            sql = "insert into PhieuKiemKe values(" +
                  "N'"+pkk.MaPhieuKK+"',N'"+pkk.TenPhieuKK+"',convert(datetime,'"+pkk.NgayKK.ToShortDateString()+"',"+type+"),N'"+pkk.MaNV+"')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        //Sua thong tin phieu kiem ke
        public bool updatePhieuKK(PhieuKiemKe pkk, string makk)
        {
            int type = uti.GetTypeDate();
            sql = "update PhieuKiemKe set MaPhieuKK=N'" + pkk.MaPhieuKK + "', TenPhieuKK=N'" + pkk.TenPhieuKK + "',NgayKiemKe=convert(datetime,'" + pkk.NgayKK.ToShortDateString() + "'," + type + "),MaNV=N'" + pkk.MaNV + "' " +
                "where MaPhieuKK=N'"+makk+"'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        //Lay thong tin CT phiem ke them ma phieu kk
        public DataTable getCTKiemKe(string makk)
        {
            sql = "select MaCTKK,c.MaPhieuKK as 'MaPhieuKK1',a.MaBanSach,TenDauSach,TinhTrang, TrangThai " +
                "from BanSach a join CTKiemKe b on a.MaBanSach=b.MaBanSach " +
                "join PhieuKiemKe c on b.MaPhieuKK=c.MaPhieuKK " +
                " join DauSach d on a.MaDauSach=d.MaDauSach "+
                "where b.MaPhieuKK=N'" + makk + "'";
            return conn.GetDataTable(sql);
        }
        public bool insertCTPhieuKK(CTKiemKe CTKK)
        {
            sql = "insert into CTKiemKe values (N'"+CTKK.MaCTKK+"',N'" + CTKK.MaPhieuKK + "',N'"+CTKK.MaBanSach+"')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        public bool updateCTPhieuKK(CTKiemKe ctkk)
        {
            sql = "update CTKiemKe set MaBanSach=N'" + ctkk.MaBanSach + "' where MaCTKK=N'" + ctkk.MaCTKK + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        #endregion 
      
        #region Dùng cho thanh lý
        public PhieuThanhLy getPhieuTL_object(string maTL)
        {
                sql = "select * from PhieuThanhLy where MaPhieuTL='" + maTL + "'";
                DataTable dtb = conn.GetDataTable(sql);
                if (dtb.Rows.Count - 1 != 0)
                {
                    DataRow dr = conn.GetDataTable(sql).Rows[0];
                    phieuTL.MaPhieuTL = dr["MaPhieuTL"].ToString();
                    phieuTL.TenPhieuTL = dr["TenPhieuTL"].ToString();
                    phieuTL.NgayTL = Convert.ToDateTime(dr["NgayTL"]);
                    phieuTL.MaNV = dr["MaNV"].ToString();
                    return phieuTL;
                }
                else
                    return phieuTL;
        }
        public bool insertPhieuTL(PhieuThanhLy phieu)
        { 
            int type=uti.GetTypeDate();
            sql = "insert into PhieuThanhLy values (N'" + phieu.MaPhieuTL + "',N'" + phieu.TenPhieuTL + "',convert(datetime,'" + phieu.NgayTL + "'," + type + "),N'" + phieu.MaNV + "')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        public DataTable getCTThanhLy(string maTL)
        {
            sql = "select MaCTThanhLy,MaPhieuTL,a.MaBanSach,TenDauSach, TinhTrang, TrangThai " +
                  "from CTPhieuTL a join BanSach b on a.MaBanSach=b.MaBanSach " +
                  "join DauSach c on b.MaDauSach=c.MaDauSach "+
                  "where MaPhieuTL=N'"+maTL+"'";
            return conn.GetDataTable(sql);
        }
        public bool insertCTThanhLy(CTThanhLy ct)
        {
            sql = "insert into CTPhieuTL values (N'"+ct.MaCTThanhLy+"',N'"+ct.MaPhieuTL+"',N'"+ct.MaBanSach+"')";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        public bool updateBanSach_TL(string mabansach, int k)
        {
            if(k==1)
                sql = "update BanSach set TrangThai=N'Thanh lý' where MaBanSach=N'" + mabansach + "'";
            else
                sql = "update BanSach set TrangThai=N'Sẵn sàng' where MaBanSach=N'" + mabansach + "'";
            if (conn.ExecuteQuery(sql) == true)
                return true;
            return false;
        }
        #endregion
       
        #region In ấn
        public DataTable getSource_BanSach(string madausach)
        {
            sql = "select * from BanSach where MaDauSach=N'" + madausach + "'";
            return conn.GetDataTable(sql);
        }
        #endregion

    }
}
 